const {articleModels,diaryModels} = require("../../models");
const path = require("path");//用于处理文件和目录路径的工具，提供了一些方法来操作路径，如拼接路径、获取目录名、获取文件名等。
const mkdir = require("../../lib/mkdir");


//获取数据总览
exports.getOverview = async (req, res) => {
  // try {
    let article = await articleModels.getArticleCount(-1, -1,"",0);
    let gallery = await articleModels.getArticleCount(-1, -1,"",1);
    let diary = await diaryModels.getDiaryCount("");
    // 修复路径拼接，使用 path.join 自动处理分隔符
    let file = await mkdir.getDirectorySize(path.join(__dirname, '../../data/files'));
    let room=0;
    if(file<1024*1024){
      room = Math.round(file/1024*100)/100+' KB';
    } else{
      room = Math.round(file/1024/1024*100)/100+' MB';
    }
    let data = {
      article:article[0].count,
      gallery:gallery[0].count,
      diary:diary[0].count,
      file:room,
    }
    res.send({
      code: 200,
      data: data
    })
  // } catch (error) {
  //   res.send({
  //     code: 400,
  //     data: error,
  //     msg: "获取数据总览失败"
  //   })
  // }
}